import request from '@/utils/request'
import {
  urlParam
} from '@/utils/index'

export function addTestSpotCheck(param) {
  if (param.time && param.time.length) {
    param.startTime = param.time[0]
    param.endTime = param.time[1]
  } else {
    param.startTime = ''
    param.endTime = ''
  }
  return request.post('/spotCheck/test', param)
}

export function getTestSpotCheck(param) {
  if (param.time && param.time.length) {
    param.startTime = param.time[0]
    param.endTime = param.time[1]
  } else {
    param.startTime = ''
    param.endTime = ''
  }
  return request.get('/spotCheck/test?' + urlParam(param))
}

export function spotCheckTestList(param) {
  if (param.time && param.time.length) {
    param.startTime = param.time[0]
    param.endTime = param.time[1]
  } else {
    param.startTime = ''
    param.endTime = ''
  }
  return request.get('/test/spotCheck?' + urlParam(param))
}

export function spotCheckTestSum(param) {
  if (param.time && param.time.length) {
    param.startTime = param.time[0]
    param.endTime = param.time[1]
  } else {
    param.startTime = ''
    param.endTime = ''
  }
  return request.get('/test/spotCheckSum?' + urlParam(param))
}

export function testList(queryParam) {
  if (queryParam.year === null) {
    delete queryParam.year
  }
  return request.get('/test?' + urlParam(queryParam))
}

export function bindClassOrCurriculum(id, values) {
  return request.post(`/test/${id}/type`, values)
}

export function getClassOrCurriculum(id) {
  return request.get(`/test/${id}/type`)
}

export function testInfo(id) {
  return request.get(`/test/id:${id}`)
}

export function addUpTest(test) {
  return request.post('/test', test)
}

export function commitCheck(testId, checkPeople) {
  const fd = new FormData()
  fd.set('checkPeople', checkPeople)
  return request.put(`/test/${testId}/commitCheck`, fd)
}

export function rejectCheck(testId, msg) {
  return request.put(`/test/${testId}/rejectCheck?msg=${msg}`)
}

export function commitReview(testId, reviewPeople) {
  const fd = new FormData()
  fd.set('reviewPeople', reviewPeople)
  return request.put(`/test/${testId}/commitReview`, fd)
}

export function rejectReview(testId, msg) {
  return request.put(`/test/${testId}/rejectReview?msg=${msg}`)
}

export function review(testId) {
  return request.put(`/test/${testId}/review`)
}

export function addQuestionToTest(testId, testStructureId, questionId, score) {
  const fd = new FormData()
  fd.set('questionId', questionId)
  fd.set('score', score)
  return request.post(`test/${testId}/testStructure/${testStructureId}/question`, fd)
}

export function addQuestionToTest2(testId, testStructureId, questionId, score) {
  const fd = new FormData()
  fd.set('questionId', questionId)
  fd.set('score', score)
  fd.set("isUpdateProvenance", 1);
  return request.post(`test/${testId}/testStructure/${testStructureId}/question`, fd)
}

export function getquestionScore(testId, testStructureId, questionId) {
  return request.get(`test/${testId}/testStructure/${testStructureId}/question/${questionId}`)
}

export function questionSort(testId, testStructureId, questionId, sort) {
  const fd = new FormData()
  fd.set('sort', sort)
  return request.put(`test/${testId}/testStructure/${testStructureId}/question/${questionId}`, fd)
}

export function deleteTestQuestion(testId, testStructureId, questionId) {
  return request.delete(`test/${testId}/testStructure/${testStructureId}/question/${questionId}`)
}

export function delTest(id) {
  return request.delete("/test/delTest", {
    data: {
      id: id
    }
  });
}

export function rejectCheckMultiple(ids) {
  return request.put("/test/rejectCheckMultiple", {
    ids: ids
  }
  );
}
